package cn.wzb.hrm.web.controller;

import cn.wzb.hrm.dto.VerifSMSCodeDto;
import cn.wzb.hrm.service.IVerifyCodeService;
import cn.wzb.hrm.util.AjaxResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

//验证码
@RestController
public class VerifycodeControlle {

    @Autowired
    private IVerifyCodeService verifycodeService ;

    //图片验证码
    @GetMapping("/verifycode/imageCode/{imageCodeKey}")
    public String createImageCode(@PathVariable("imageCodeKey") String imageCodeKey){
        return verifycodeService.createImageCode(imageCodeKey);
    }

    //短息验证码
    @PostMapping("/verifycode/sendSmsCode")
    public AjaxResult sendSmsCode(@RequestBody VerifSMSCodeDto verifSMSCodeDto){
        try{
            verifycodeService.sendSmsCode(verifSMSCodeDto);
        }catch (RuntimeException e){
            e.printStackTrace();
            return AjaxResult.me().setSuccess(false).setMessage(e.getMessage());
        }catch (Exception e){
            e.printStackTrace();
            return AjaxResult.me().setSuccess(false).setMessage("服务器异常,我们正在殴打程序员");
        }
        return AjaxResult.me();
    }

}
